﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Classes
{
   /// <summary>
   /// Contains static methods for switching between state names and abbreviations.
   /// </summary>
   public class StateList
   {
      private static readonly List<String> names = new List<String>(){"Alabama", "Alaska", "Arizona", "Arkansas", "California",
         "Colorado", "Connecticut", "Delaware", "Washington, D.C.", "Flordia", "Georgia", "Hawaii",
         "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Lousisiana", "Maine",
         "Maryland", "Massachussetts", "Michigan", "Minnesota", "Mississippi", "Missouri",
         "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York",
         "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania",
         "Puerto Rico", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas",
         "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"};
      private static readonly List<String> abbreviations = new List<String>(){ "AL", "AK", "AZ", "AR", "CA", "CO", "CT",
         "DE", "DC", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA",
         "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK",
         "OR", "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"};
         
      static private SortedList<String, String> abbrKey=null, nameKey=null;
      
      /// <summary>
      /// Converts a state's name into its abbreviation.
      /// </summary>
      /// <param name="name">String of state name</param>
      /// <returns></returns>
      public static String ConvertNameToAbbreviation(String name)
      {
         if (nameKey == null)
            Setup();
         if (nameKey.ContainsKey(name))
            return nameKey[name];
         else return "State Not Found";
      }

      /// <summary>
      /// Converts a state's abbreviation into its full name.
      /// </summary>
      /// <param name="abbr">String abbreviation for a state</param>
      /// <returns></returns>
      public static String ConvertAbbreviationToName(String abbr)
      {
         if (nameKey == null || abbrKey == null)
            Setup();
         if (abbrKey.ContainsKey(abbr))
            return abbrKey[abbr];
         else return "State Not Found";
      }
      
      public static List<String> Names { get { return names; } }
      
      public static List<String> Abbreviations { get { return abbreviations; } }

      /// <summary>
      /// Combines 2 static String[] into a pair of SortedLists.
      /// </summary>
      static private void Setup()
      {
         abbrKey = new SortedList<string,string>();
         nameKey = new SortedList<string,string>();
         for (int i = 0; i < names.Count; ++i)
         {
            abbrKey.Add(abbreviations[i], names[i]);
            nameKey.Add(names[i], abbreviations[i]);
         }
      }
   }
}
